package test.socket;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import org.junit.Test;
import hyl.core.fun.MyByte;

public class testbytebuffer {
	
	public void test1() {
		//bytebuffer 不支持超界
		ByteBuffer byteBuffer = ByteBuffer.allocate(300);
		byteBuffer.put("sda234235f".getBytes(Charset.forName("ASCII")));
		byteBuffer.put("23124".getBytes(Charset.forName("ASCII")));
		byteBuffer.flip();	
		System.out.println(byteBuffer.capacity()+"  "+byteBuffer.limit());
		byte[] bb=MyByte.byteBuf2bytes(byteBuffer);
		System.out.println(new String(bb, Charset.forName("ASCII")));
	}
	
	@Test
	public void test2() throws IOException {
		// ByteArrayOutputStream 支持追加  30 是写入缓存
		  ByteArrayOutputStream bOutput = new ByteArrayOutputStream(30);
		  bOutput.write("sda234235f".getBytes());
		  bOutput.reset();
		  bOutput.write("123新版本".getBytes());	
		  byte b [] = bOutput.toByteArray();
		  System.out.println(new String(b));
	}
}
